package com.ksd.dao.impl;

import com.ksd.dao.INoticeDAO;
import com.ksd.pojo.Notice;
import org.hibernate.SessionFactory;

import java.util.List;

public class NoticeDAO implements INoticeDAO {

    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public List findAll() {
        return sessionFactory.getCurrentSession().createQuery("from Notice").list();
    }

    public Notice findById(String id) {
        return (Notice) sessionFactory.getCurrentSession().get(Notice.class,
                new Integer(id));
    }

    @Override
    public void insert(Notice notice) {
        sessionFactory.getCurrentSession().save(notice);
    }

    public void update(Notice notice) {
        sessionFactory.getCurrentSession().update(notice);
    }

    public void delete(String id) {
        Object p = sessionFactory.getCurrentSession().load(Notice.class, new Integer(id));
        sessionFactory.getCurrentSession().delete(p);
    }

}
